package com.woniu.his.dms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.dms.client.CaseModelCatalogClient;
import com.woniu.his.dms.client.param.AddCaseModelCatalogClientParam;
import com.woniu.his.dms.client.result.CaseModelCatalogResult;
import com.woniu.his.dms.service.CaseModelCatalogService;
import com.woniu.his.dms.service.dto.CaseModelCatalogDto;
import com.woniu.his.dms.service.param.AddCaseModelCatalogParam;
import com.woniu.his.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version: java version 1.8
 * @Author: ZJH
 * @description:
 * @date: 2022-11-29 21:02
 */
@RestController
@RequestMapping("dms")
@Slf4j
public class CaseModelCatalogApiImpl implements CaseModelCatalogClient {

    @Resource
    private CaseModelCatalogService caseModelCatalogService;

    @Override
    public Result<Boolean> addCaseModelCatalogService(AddCaseModelCatalogClientParam param) {
        log.info("新增病历模板目录参数：{}",param);
        AddCaseModelCatalogParam addCaseModelCatalogParam = BeanUtil.copyProperties(param, AddCaseModelCatalogParam.class);
        Boolean bool = caseModelCatalogService.addCaseModelCatalogService(addCaseModelCatalogParam);
        return Result.getInstance(Boolean.class).setData(bool);
    }

    @Override
    public Result<Boolean> deleteCaseModelCatalogById(Long id) {
        log.info("删除病历模板目录参数：{}",id);
        Boolean bool = caseModelCatalogService.deleteCaseModelCatalogById(id);
        return Result.getInstance(Boolean.class).setData(bool);
    }

    @Override
    public Result<Boolean> updateCaseModelCatalogName(Long id, String catalogName) {
        log.info("更新病历模板目录名称参数：{} {}",id,catalogName);
        Boolean bool = caseModelCatalogService.updateCaseModelCatalogName(id, catalogName);
        return Result.getInstance(Boolean.class).setData(bool);
    }

    @Override
    public Result<List<CaseModelCatalogResult>> queryCaseModelCatalog() {
        log.info("查询病历模板目录");
        List<CaseModelCatalogDto> catalogDtos = caseModelCatalogService.queryCaseModelCatalog();
        List<CaseModelCatalogResult> catalogResult = BeanUtil.copyToList(catalogDtos, CaseModelCatalogResult.class);
        return Result.getInstanceList(CaseModelCatalogResult.class).setData(catalogResult);
    }
}
